package pattern15;

import java.util.ArrayList;

/**
 * 非叶子节点
 *
 * @author wdl
 */
public class Composite extends BaseComponent {
    public Composite(String name) {
        super(name);
    }

    private ArrayList<BaseComponent> components = new ArrayList<>();

    @Override
    public void add(BaseComponent component) {
        components.add(component);
    }

    @Override
    public void remove(BaseComponent component) {
        components.remove(component);
    }

    @Override
    public void display(int depth) {
        for (int i = 0; i < depth; i++) {
            System.out.print("-");
        }
        System.out.println(name);
        for (BaseComponent component : components) {
            component.display(depth + 2);
        }
    }
}
